package hottargui.domain.gamma;

import hottargui.domain.*;

public class GammaRoundSequenceStrategyImpl implements RoundSequenceStrategy{


	private PlayerColor _currentColor;
	private State _currentState;
	private int _round;
	private StateMachine _stm;
	private DeckOfCards _deck; 


	public GammaRoundSequenceStrategyImpl(StateMachine stm, DeckOfCards deck){
		_stm = stm; 
		_deck = deck;
	}



	public PlayerColor turnCard() {

		_round = _stm.getRoundNumber();

		_currentState = _stm.getState();

		Card c = _deck.takeCardFormTopOfDeck();
		_currentColor = c.getPlayerColor();
		_deck.putCardOnDeck(c); 

		if (_currentState==State.newGame) {
			_stm.setState(State.buy, false);	  
		}
		else if (_currentState==State.endTurn) {
			if (_round == 0) {
				_stm.setState(State.buy, false);
			} else {
				_stm.setState(State.move, false);
			}
		}

		else if (_currentState==State.endRound) {
			_round += 1;
			_stm.setRound(_round);

			if (_round == 12) {
				_stm.setState(State.gameover, false);
			}
			else
			{

			_stm.addRevenue(PlayerColor.Red);
			_stm.addRevenue(PlayerColor.Green);
			_stm.addRevenue(PlayerColor.Blue);
			_stm.addRevenue(PlayerColor.Yellow);

			_stm.setState(State.move, false); 
			}
		}


		//Updating references

		_stm.doUpdateDeck(_deck);
		return _currentColor;

	}



	public Player getPlayerInTurn() {
		return _stm.getPlayer(_currentColor);
	}


	//TODO Inteface
	public void doUpdateDeck(DeckOfCards deck) {
		_deck = deck;
	}



	public void setDeckOfCards(DeckOfCards deck) {
		_deck = deck;	
		Card c = _deck.takeCardFormTopOfDeck(); // TAGES AF VED TURNCARD
		_currentColor = c.getPlayerColor();
		_deck.putCardOnDeck(c);

		_stm.setState(State.move, false);
		_stm.setCurrentColor(_currentColor);


	}



	//This gamevariant does use a deck of cards. According to interface this 
	//mehod has the facevalue on witch the (current) _deck is based. 
	public int getCurrentDeckBasedDiceValue() {
		return _deck.getCurrentDeckBasedDiceValue();
	}


}



